package net.vinote.smart.platform.service.handler;

import java.sql.SQLException;

import net.vinote.smart.platform.module.database.DBManager;
import net.vinote.smart.platform.module.database.DBManagerFactory;
import net.vinote.smart.platform.module.database.DBTransaction;
import net.vinote.smart.platform.module.database.bo.BizObject;
import net.vinote.smart.platform.service.dw.handler.CommonHandler;
import net.vinote.smart.platform.service.dw.handler.HandlerPerimissionAnnotation;
import net.vinote.smart.platform.service.util.Permission;
import net.vinote.smart.platform.service.util.Permission.PermissionEnum;

/**
 * @author Seer
 * @version CodeCatalogHandler.java, v 0.1 2015年3月5日 下午2:35:49 Seer Exp.
 */
@HandlerPerimissionAnnotation(
		insert = @Permission(PermissionEnum.SMART_CODE_CATALOG_INSERT),
		update = @Permission(PermissionEnum.SMART_CODE_CATALOG_UPDATE),
		delete = @Permission(PermissionEnum.SMART_CODE_CATALOG_DELETE),
		query = @Permission(PermissionEnum.SMART_CODE_CATALOG_QUERY))
public class CodeCatalogHandler extends CommonHandler {
	@Override
	public void initDisplayForEdit(BizObject bo) {
		setReadOnly("CodeNo", true);
	}

	@Override
	protected void beforeDelete(BizObject bo, DBTransaction tx)
			throws SQLException {
		DBManager bm = DBManagerFactory.getInstance("code_library");
		tx.join(bm);
		bm.deleteWhereSql("codeNo=?", bo.getAttribute("codeNo"));
	}

}
